package roborally.program.command;

import roborally.itemsonboard.Robot;
import be.kuleuven.cs.som.annotate.Basic;
import be.kuleuven.cs.som.annotate.Raw;


/**
 * A class representing a condition that can be evaluated to be true or false for a specific robot.
 * 
 * @invar (repeated)
 * 		An ArgumentCommand must have legal arguments, as defined in the method canHaveAsArguments() at all times.
 * 		| this.canHaveAsArguments(this.getArguments())
 * 
 * @author Molderez Tom, 2de bach Ingenieurswetenschappen Computerwetenschappen-Elektrotechniek and Reniers Jorn, 2de bach Ingenieurswetenschappen Werktuigkunde-Computerwetenschappen
 * @version 1.0
 *
 */
public abstract class Condition extends ArgumentCommand {
	
	/**
	 * Creates a new Condition.
	 * 
	 * @param arguments The arguments of this command.
	 * @effect Evokes the constructor of the superclass with the argument arguments.
	 * 		| super(arguments)
	 * @throws IllegalArgumentException (repeated)
	 * 		When the arguments are not valid according to isPossibleArguments().
	 * 		| !isPossibleArguments(arguments)
	 */
	public Condition(Object...arguments) throws IllegalArgumentException {
		super(arguments);
	}
	
	/**
	 * Returns the value of this condition.
	 */
	@Basic @Raw
	public boolean getReturnValue() {
		return this.returnValue;
	}
	
	/**
	 * Sets the value of the condition to the given value.
	 * 
	 * @param returnValue The value of this condition.
	 * @post The value returned by getReturnValue() will be the given value.
	 * 		| (new this).getReturnValue() == value
	 * @note This method is protected because this method can only be invoked 
	 * by the method that has executed this condition to determine the return value.
	 */
	@Raw
	protected void setReturnValue(boolean returnValue) {
		this.returnValue = returnValue;
	}
	
	/**
	 * Executes this condition. This method is the same as execute.
	 * 
	 * @param minimumSteps The amount of basic commands we already have executed. 
	 * @param currentSteps The amount of basic commands we already passed.
	 * @param robot The robot that will be manipulated by the given program.
	 * @effect Executes this condition by checking according the procedure if the return
	 * value must be false or true.
	 * @return The new currentSteps which is equal to the given one.
	 * @throws IllegalArgumentException
	 * 		When the robot is not valid.
	 */
	@Override
	public int next(int minimumSteps, int currentSteps, Robot robot) {
		execute(robot);
		return currentSteps;
	}

	/**
	 * Stores the value of this condition.
	 */
	private boolean returnValue = false;
}